<?php

declare(strict_types=1);

namespace App\Controller\HomePage;

use App\Repository\WebhookRepository;
use Psr\Http\Message\ResponseInterface;
use Yiisoft\DataResponse\Formatter\HtmlDataResponseFormatter;
use Yiisoft\Yii\View\Renderer\ViewRenderer;

final readonly class Action
{
    public function __construct(
        private ViewRenderer $viewRenderer,
        private WebhookRepository $webhooks,
        private HtmlDataResponseFormatter $htmlFormatter,
    ) {}

    public function __invoke(): ResponseInterface
    {
        return $this->viewRenderer
            ->render(
                __DIR__ . '/template',
                [
                    'webhooks' => $this->webhooks->list(),
                ],
            )
            ->withResponseFormatter($this->htmlFormatter);
    }
}
